package com.yootoo.extpmml.smg3.loader;

import com.experian.stratman.decisionagent.business.IStrategyLoader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * 直接从classpath下读取ser策略文件
 * Created by yootoo on 2017/5/16.
 */
public class ClassPathStrategyLoader implements IStrategyLoader{
    @Override
    public InputStream getStream(String strategyName) throws IOException {
        if(strategyName.startsWith("/")){
            strategyName = strategyName.substring(1);
        }
        URL resource = this.getClass().getClassLoader().getResource(strategyName);
        if (resource == null){
            throw new FileNotFoundException("file:" + resource + " is not exists.");
        }
        InputStream is = resource.openStream();
        return is;
    }
}
